package cobra

import (
	io_cobra "clean/adapter/io/console/cobra"
	"clean/infra/config"
	"clean/infra/io"
	"clean/infra/io/driver"
	"clean/usecase"
	"github.com/spf13/cobra"
)

type ioDriver struct {
}

func init() {
	io.Register("console_cobra", &ioDriver{})
}

func (ioDriver) Create(cfg config.Config, app usecase.Input) (io_driver.Io, error) {
	return NewServerCobra(cfg, app)
}

// cw hello --name aa
type ServerCobra struct {
	root *cobra.Command
}

func NewServerCobra(cfg config.Config, app usecase.Input) (*ServerCobra, error) {
	s := &ServerCobra{
		root: &cobra.Command{
			Use:   "cw",
			Short: "welcome App",
			Long:  `用来探索clean架构`,
		},
	}
	h := io_cobra.NewHandler(app)
	h.Init(s.root)
	return s, nil
}

func (s *ServerCobra) Start() error {
	return s.root.Execute()
}
